home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 9780 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.2 KB

  1. Path: solon.com!not-for-mail
  2. From: johnb@pivotal-dm.ccmail.compuserve.com (John Bain)
  3. Newsgroups: comp.lang.c,comp.lang.c.moderated
  4. Subject: Re: Integral promotion problem
  5. Date: 13 Mar 1996 06:40:50 -0600
  6. Organization: Pivotal Technologies Ltd.
  7. Sender: clc@solutions.solon.com
  8. Approved: clc@solutions.solon.com
  9. Message-ID: <4i6foi$p2p@solutions.solon.com>
  10. References: <31404525.26295649@dub-news-svc-3.compuserve.com> <314405dd.13127805@dub-news-svc-3.compuserve.com>
  11. NNTP-Posting-Host: solutions.solon.com
  12. X-Newsreader: Forte Agent .99d/32.182
  13.  
  14. I wrote:
  15.  
  16. >The reference section of K&R2 (the best
  17. >definition I have, as I do not have a copy of the standard) says, in its
  18. >definition of '~' (A7.4.6):
  19. >
  20. >"The integral promotions are performed.  If the operand is unsigned, the
  21. >result is computed by subtracting the value from the largest value of
  22. >the promoted type.  If the operand is signed, the result is computed by
  23. >converting the promoted operand to the corresponding unsigned type,
  24. >applying ~, and converting it back to the unsigned type."
  25. >
  26. >I didn't believe that the implementation defined unsigned->signed
  27. >conversions were happening, but I didn't believe the results I was
  28. >seeing either!
  29. >
  30. >Incidentally, I assume that when it says "if the operand is unsigned" it
  31. >means _before_ promotion?
  32.  
  33. I have no idea what I was thinking about when I wrote this.
  34.  
  35. It seems to me that it must mean _after_ promotion, and is likely to
  36. result in an implementation defined value whenever ~ is applied to an
  37. unsigned short on an implementation where unsigned shorts promote to
  38. ints.
  39.  
  40. I.e. (assuming a is unsigned short) in evaluating ~a, a is first
  41. promoted to int (well defined), the int value is converted to unsigned
  42. int (well defined), ~ is applied to the unsigned value (well defined),
  43. and the unsigned result is converted back to int (implementation
  44. defined, if, as seems likely, the value of the unsigned int result
  45. cannot be represented in an int.)
  46.  
  47. Is this interpretation correct?
  48.  
  49. Cheers,
  50.  
  51. John
  52. -----------------------------------------------------------------
  53. John Bain                  
  54. johnb@pivotal-dm.ccmail.compuserve.com 
  55. -----------------------------------------------------------------
  56.